package com.homedo.odin.solution.enumcode.statistics;

import java.util.Arrays;
import java.util.stream.Collectors;
import lombok.Getter;

/**
 * 统计页位置代码
 */
@Getter
public enum LogPositionCodeEnum {
    SOLUTION_INDEX_TOP("solution_index_top", "方案管首页顶部位置"),
    SOLUTION_INDEX_BOTTOM("solution_index_bottom", "方案管首页底部位置");

    private String dbValue;
    private String displayValue;

    LogPositionCodeEnum(String dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }


    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(String dbValue) {
        return Arrays.stream(LogPositionCodeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(LogPositionCodeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(String dbValue) {
        return Arrays.stream(LogPositionCodeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }

    public static String getDbValues() {
        return Arrays.stream(LogPositionCodeEnum.values()).map(data -> data.getDbValue())
                .collect(Collectors.joining(","));
    }
}
